# coding=utf-8

# system
import datetime
import pickle
import StringIO

# appengine
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

# local
import base

class OneBoxFeedPage(webapp.RequestHandler):
  def get(self):
    shard_id = self.request.get("shard")
    if not shard_id:
      shard_id = '0'
    persons = base.Person().all().filter('shard =', base.GetShardFromId(shard_id))

    # Hack to modify late_update timezone. Should find better way to do this.
    my_persons = [person for person in persons]
    for person in my_persons:
      person.last_update = person.last_update + datetime.timedelta(hours=8)
    # End of hack
    
    template_values = base.GetPersonsTemplate(self, my_persons)
    path = base.GetTemplatePath('onebox_feed.html')
    output = template.render(path, template_values)
    
    output = output.replace("[t]", "\t");
    output = output.replace("[n]", "\n");
    self.response.out.write(output)
